extends ../main

block append body
    div#menuAdd.form-element
        div.col-lg-12(style="margin-top:40px")
            div.panel.form-element-padding.panel-info
                div.panel-heading
                    h3#header.panel-title 权限添加
                div.panel-body
                    div.col-lg-12(style="padding-top:20px;")
                        form.form-horizontal
                            div.form-group
                                label.col-sm-1.control-label.text-center(for="priviName") 权限名称
                                div.col-sm-3
                                    input#priviName.form-control(type="text",placeholder="权限名称",v-model="priviName")
                                    input#priviId(type="hidden")
                            div.form-group
                                label.col-sm-1.control-label.text-center(for="addmenus") 添加菜单
                                div.col-sm-10
                                    div.ue-container
                                        select#addmenus(multiple="multiple" size="10" name="addmenus" class="addmenus")
                    div.form-group.col-sm-offset-4
                        div.col-sm-1
                            input.btn.btn-info(type="button",value="返回",onclick="location.href='/manager/main/privilege'")
                        div.col-sm-1
                            input#submit.btn.btn-primary(type="button",value="提交更改",@click="submitData")

block append footer
    script(type="text/javascript").
        $(function() {

            var priviId = '#{priviId}';
            var priviName = '#{priviName}';

            var app = new Vue({
                el: "#content",
                data: {
                    id:priviId||0,
                    priviName:priviName||""
                },
                methods: {
                    init: function () {

                        zxlib.fpost("/manager/main/getPmenus", {priviId:app.id}, function (data) {
                            console.log(data)
                            var addmenus = $('.addmenus').doublebox({
                                nonSelectedListLabel: '选择菜单',
                                selectedListLabel: '授权角色菜单',
                                preserveSelectionOnMove: 'moved',
                                moveOnSelect: false,
                                nonSelectedList: data.data.pmenu,
                                selectedList: data.data.smenu,
                                optionValue: "id",
                                optionText: "menuName",
                                doubleMove: true,
                            });


                        }, function (data) {
                            zxlib.showAlert("error", data);
                        });

                    },
                    submitData:function () {
                        var p = {
                            priviId:app.id,
                            priviName:app.priviName,
                            menuIds:$('.addmenus').val().join(',')
                        }
                        zxlib.fpost("/manager/main/addPrivis",p,function (data) {
                            zxlib.showAlert("success",data.msg,1000,function () {
                                location.reload();
                            });

                        },function (data) {
                            zxlib.showAlert("error",data);
                        });
                    }
                }
            });
            app.init();
        });